{include file='header'/}
<body class="pear-admin">
<form class="layui-form" action="/app/admin/admin/add" method="post">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label required">{:trans('Role_group',[],'admin')}</label>
                <div class="layui-input-block">
                    <div name="roles" id="admin-add-roles" value=""></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">{:trans('Username',[],'admin')}</label>
                <div class="layui-input-block">
                    <input type="text" name="username" required lay-verify="required" autocomplete="off"
                           placeholder="{:trans('Please enter', ['%s%' => trans('Username',[],'admin')])}"
                           class="layui-input" value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">{:trans('Nickname',[],'admin')}</label>
                <div class="layui-input-block">
                    <input type="text" name="nickname" required lay-verify="required" autocomplete="off"
                           placeholder="{:trans('Please enter', ['%s%' => trans('Nickname',[],'admin')])}"
                           class="layui-input" value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">{:trans('Password',[],'admin')}</label>
                <div class="layui-input-block">
                    <input type="password" name="password" autocomplete="off" required lay-verify="required|pwd"
                           placeholder="{:trans('Please enter', ['%s%' => trans('Password',[],'admin')])}"
                           class="layui-input" value="">
                </div>
                <tip>
                    {:trans('Composed of letters, numbers, special characters, any two types, 6-15 digits',[],'admin')}
                </tip>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">{:trans('Email',[],'admin')}</label>
                <div class="layui-input-block">
                    <input type="email" name="email" autocomplete="off" lay-verify="email"
                           placeholder="{:trans('Please enter', ['%s%' => trans('Email',[],'admin')])}"
                           class="layui-input"
                           value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">{:trans('Mobile',[],'admin')}</label>
                <div class="layui-input-block">
                    <input type="text" name="mobile" autocomplete="off" lay-verify="phone"
                           placeholder="{:trans('Please enter', ['%s%' => trans('Mobile',[],'admin')])}"
                           class="layui-input"
                           value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">{:trans('Status')}</label>
                <div class="layui-input-block">
                    <input type="checkbox" id="admin-status" lay-filter="admin-status" lay-skin="switch"/>
                    <input type="text" style="display:none" name="status" value="1"/>
                </div>
            </div>

        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-sm" lay-submit=""
                    lay-filter="data-save">
                <i class="layui-icon layui-icon-ok"></i>
                {:trans('Save')}
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                {:trans('Reset')}
            </button>
        </div>
    </div>
</form>

</body>
{include file='footer'/}
<script>
  layui.use(["form", "iconPicker", "util", "xmSelect"], function () {
    var $ = layui.$;
    var form = layui.form;
    form.render();

    //自定义密码表单验证
    form.verify({
      pwd: function (value, elem) {
        if (!/^[^\u4e00-\u9fa5]*$/.test(value)) {
          return "{:trans('Password cannot appear in Chinese',[],'admin')}";
        }
        if (!/^(?![a-zA-Z]+$)(?!\d+$)(?![^\da-zA-Z\s]+$).{6,15}$/.test(value)) {
          return "{:trans('Composed of letters, numbers, special characters, any two types, 6-15 digits',[],'admin')}";
        }
      }
    });

    // 字段 角色 roles
    layui.$.ajax({
      url: "/app/admin/role/select?format=tree",
      dataType: "json",
      success: function (res) {
        if (!top.Admin.Account.isSupperAdmin) {
          layui.each(res.data, function (k, v) {
            v.disabled = true;
          });
        }
        layui.xmSelect.render({
          el: "#admin-add-roles",
          name: "roles",
          initValue: [],
          data: res.data,
          layVerify: "required",
          theme: {color: 'var(--global-primary-color)'},
          tree: {show: true, expandedKeys: true, strict: false},
          toolbar: {show: true, list: ["ALL", "CLEAR", "REVERSE"]},
        })
        if (res.code !== 200) {
          return layui.huiAdmin.showToast('error', res.msg);
        }
      }
    });

    // 字段 状态 status
    layui.use(["form"], function () {
      layui.$("#admin-status").attr("checked", layui.$('input[name="status"]').val() != 0);
      layui.form.render();
      layui.form.on("switch(admin-status)", function (data) {
        layui.$('input[name="status"]').val(this.checked ? 1 : 0);
      });
    })

  })
</script>
